package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotion.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 插入菜品数据
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);
    /**
     * 菜品分页
     * @param dishPageQueryDTO
     */
    Page<DishVO> pageQuerry(DishPageQueryDTO dishPageQueryDTO);
    /**
     * 根据Id查找菜品及口味
     */
    @Select("select * from dish where id = #{id}")
    Dish getbyid(Long id);
    @Select("select * from dish_flavor where dish_id = #{id}")
    List<DishFlavor> getfalvorbyid(Long id);

    /**
     * 根据主键删除菜品
     * @param id
     */
    @Delete("delete from dish where id =#{id}")
    void deleteById(Long id);

    /**
     * 修改菜品及口味
     * @param dish
     */
    //修改菜品
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据categoryId查询菜品
     * @param dish
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId} and status = #{status}")
    List<Dish> list(Dish dish);
    /**
     * 根据分类Id查询菜品
     * @param categoryId
     * @return
     */
    List<Dish> getByCategoryId(Long categoryId);

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    List<Dish> getBySetmealId(Long id);
    /**
     * 更改菜品售卖状态
     * @param status
     */
    @Update("update dish set status = #{status} where id = #{id}")
    void setStatus(Integer status,Long id);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
